package com.ibs.hadoop.hbase.service.impl;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.List;
import java.util.Map;

import com.ibs.hadoop.hbase.bean.UseComplaintBaseClass;
import com.ibs.hadoop.hbase.util.IOutils;

public class LocalCacheFileProcess {

    /**
     * 进行本地文件写入方法
    * 方法描述
    * @param path
    * @param result
    * @创建日期 2016年11月7日
    */
    public void writeObjectFile(String path, Map<String, List<UseComplaintBaseClass>> result) {
        FileOutputStream output = null;
        BufferedOutputStream buffOutput = null;
        ObjectOutputStream outputobject = null;
        try {
            output = new FileOutputStream(path);
            buffOutput = new BufferedOutputStream(output);
            outputobject = new ObjectOutputStream(buffOutput);

            outputobject.writeObject(result);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IOutils.closeStream(outputobject);
            IOutils.closeStream(buffOutput);
            IOutils.closeStream(output);
        }

    }

    /**
     * 进行本地序列化文件的读取
    * 方法描述
    * @param path
    * @return
    * @创建日期 2016年11月7日
    */
    @SuppressWarnings("unchecked")
    public Map<String, List<UseComplaintBaseClass>> readObjectFile(String path) {
        Map<String, List<UseComplaintBaseClass>> result = null;

        FileInputStream input = null;
        BufferedInputStream bufferRead = null;
        ObjectInputStream objectInput = null;

        try {
            input = new FileInputStream(path);
            bufferRead = new BufferedInputStream(input);
            objectInput = new ObjectInputStream(bufferRead);

            result = (Map<String, List<UseComplaintBaseClass>>) objectInput.readObject();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IOutils.closeStream(objectInput);
            IOutils.closeStream(bufferRead);
            IOutils.closeStream(input);
        }

        return result;
    }

}
